module.exports = {
    configureWebpack: {
        devServer: {
            port: 9999, //端口号
            //open: true, //启动项目开启浏览器
            // 接口编写的地方
            before(app) {
                // 模板
                // app.get('请求地址', (req, res) => {
                //     res.json({
                //         xinxi
                //     })
                // })
                //用户信息池
                let userpoor = [
                    { username: 'xiaod', password: '123456' },
                    { username: 'admin', password: '123456' }
                ]

                //注册接口
                app.get('/api/register', (req, res) => {
                    const { username, password } = req.query;
                    const userlength = userpoor.filter(v => v.username == username).length
                    if (userlength > 0) {
                        res.json({
                            success: false,
                            message: '用户名已存在'
                        })
                    } else {
                        res.json({
                            success: true,
                            message: '注册成功'
                        })
                    }
                })

                let tokenKey = 'plm';
                //登录接口
                app.get('/api/login', (req, res) => {
                    const { username, password } = req.query;
                    if ((username == 'xiaod' && password == '123456') || (username == 'admin' && password == '123456')) {
                        res.json({
                            code: 0,
                            message: '登录成功',
                            token: tokenKey + '-' + username + '-' + (new Date().getTime() + 60 * 60)
                        })
                    } else {
                        res.json({
                            code: 1,
                            message: '账号或密码错误'
                        })
                    }
                })

                //首页轮播图数据接口
                app.get('/api/banner', (req, res) => {
                    res.json({
                        data: [{
                            url: 'https://m.xdclass.net',
                            image: 'https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/xdclass_pro/bannner/1901/learn.png'
                        },
                        {
                            url: 'https://m.xdclass.net',
                            image: 'https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/upload/banner/devpay.png'
                        },
                        {
                            url: 'https://m.xdclass.net',
                            image: 'https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/xdclass_pro/bannner/1901/bat.png'
                        }]
                    })
                })

                //滚动分类接口
                app.get('/api/rollinglist', (req, res) => {
                    res.json({
                        data: [
                            [
                                {
                                    url: 'https://m.xdclass.net',
                                    image: 'https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/xdclass_pro/bannner/1901/learn.png',
                                    label: '分类一'
                                },
                                {
                                    url: 'https://m.xdclass.net',
                                    image: 'https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/xdclass_pro/bannner/1901/learn.png',
                                    label: '分类一'
                                },
                                {
                                    url: 'https://m.xdclass.net',
                                    image: 'https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/xdclass_pro/bannner/1901/learn.png',
                                    label: '分类一'
                                },
                                {
                                    url: 'https://m.xdclass.net',
                                    image: 'https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/xdclass_pro/bannner/1901/learn.png',
                                    label: '分类一'
                                },
                                {
                                    url: 'https://m.xdclass.net',
                                    image: 'https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/xdclass_pro/bannner/1901/learn.png',
                                    label: '分类一'
                                },
                                {
                                    url: 'https://m.xdclass.net',
                                    image: 'https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/xdclass_pro/bannner/1901/learn.png',
                                    label: '分类一'
                                },
                                {
                                    url: 'https://m.xdclass.net',
                                    image: 'https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/xdclass_pro/bannner/1901/learn.png',
                                    label: '分类一'
                                },
                                {
                                    url: 'https://m.xdclass.net',
                                    image: 'https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/xdclass_pro/bannner/1901/learn.png',
                                    label: '分类一'
                                },
                                {
                                    url: 'https://m.xdclass.net',
                                    image: 'https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/xdclass_pro/bannner/1901/learn.png',
                                    label: '分类一'
                                },
                                {
                                    url: 'https://m.xdclass.net',
                                    image: 'https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/xdclass_pro/bannner/1901/learn.png',
                                    label: '分类一'
                                },
                            ],
                            [
                                {
                                    url: 'https://m.xdclass.net',
                                    image: 'https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/xdclass_pro/bannner/1901/bat.png',
                                    label: '分类一'
                                },
                                {
                                    url: 'https://m.xdclass.net',
                                    image: 'https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/xdclass_pro/bannner/1901/bat.png',
                                    label: '分类一'
                                },
                                {
                                    url: 'https://m.xdclass.net',
                                    image: 'https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/xdclass_pro/bannner/1901/bat.png',
                                    label: '分类一'
                                },
                                {
                                    url: 'https://m.xdclass.net',
                                    image: 'https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/xdclass_pro/bannner/1901/bat.png',
                                    label: '分类一'
                                },
                                {
                                    url: 'https://m.xdclass.net',
                                    image: 'https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/xdclass_pro/bannner/1901/bat.png',
                                    label: '分类一'
                                },
                                {
                                    url: 'https://m.xdclass.net',
                                    image: 'https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/xdclass_pro/bannner/1901/bat.png',
                                    label: '分类一'
                                },
                                {
                                    url: 'https://m.xdclass.net',
                                    image: 'https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/xdclass_pro/bannner/1901/bat.png',
                                    label: '分类一'
                                },
                                {
                                    url: 'https://m.xdclass.net',
                                    image: 'https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/xdclass_pro/bannner/1901/bat.png',
                                    label: '分类一'
                                },
                                {
                                    url: 'https://m.xdclass.net',
                                    image: 'https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/xdclass_pro/bannner/1901/bat.png',
                                    label: '分类一'
                                },
                                {
                                    url: 'https://m.xdclass.net',
                                    image: 'https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/xdclass_pro/bannner/1901/bat.png',
                                    label: '分类一'
                                },
                            ],
                        ]
                    })
                })
            }
        }
    },

    css: {
        loaderOptions: {
            stylus: {
                'resolve url': true,
                'import': [
                    './src/theme'
                ]
            }
        }
    },

    pluginOptions: {
        'cube-ui': {
            postCompile: true,
            theme: true
        }
    }
}
